
import { _decorator, Component, Node, instantiate, Label } from 'cc';
import { Watcher } from '../misc/Watcher';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = TestManager
 * DateTime = Mon Mar 14 2022 23:33:46 GMT+0800 (中国标准时间)
 * Author = 酸菜鱼233
 * FileBasename = TestManager.ts
 * FileBasenameNoExtension = TestManager
 * URL = db://assets/scripts/test/TestManager.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/en/
 *
 */
 
@ccclass('TestManager')
export class TestManager extends Component {
    @property({type:Node})
	quadNode:Node
	@property({type:Node})
	groundNode:Node
	@property({type:Label})
	label:Label

	watcher=new Watcher<number>(0)
    start () {
		this.watcher.onChange(v=>{
			this.label.string=String(v)
		})
    }

	update(){
		let node=instantiate(this.quadNode)
		this.groundNode.addChild(node)
		let x=Math.random()*12-6
		let y=Math.random()*20-10
		node.setPosition(x,y,0)
		this.watcher.set(this.watcher.get()+1)
	}
	onDestroy(){
		this.watcher.dispose()
	}
}
